package mr.zhang.service.impl;

import mr.zhang.dao.MerchantPropertyDao;
import mr.zhang.dao.domain.MerchantProperty;
import mr.zhang.service.MerChantPropertyService;
import mr.zhang.util.PageModelMerChantProperty;

import java.util.List;



public class MerChantPropertyServiceImpl implements MerChantPropertyService {

	private MerchantPropertyDao merchantPropertyDao;

	public MerchantPropertyDao getMerchantPropertyDao() {
		return merchantPropertyDao;
	}

	public void setMerchantPropertyDao(MerchantPropertyDao merchantPropertyDao) {
		this.merchantPropertyDao = merchantPropertyDao;
	}

	// 添加商家信息
	@Override
	public void saveMerchantProperty(MerchantProperty merchantProperty) {
		// TODO Auto-generated method stub
		this.merchantPropertyDao.saveMerchantProperty(merchantProperty);

	}

	// 删除商家信息
	@Override
	public void deleteMerchantProperty(int id) {
		// TODO Auto-generated method stub
		this.merchantPropertyDao.deleteMerchantProperty(id);

	}

	// 更新商家信息
	@Override
	public void updateMerchantProperty(MerchantProperty merchantProperty) {
		// TODO Auto-generated method stub

		this.merchantPropertyDao.updateMerchantProperty(merchantProperty);

	}

	// 根据id查询商家信息
	@Override
	public MerchantProperty queryMerchantPropertyById(int id) {
		// TODO Auto-generated method stub
		return this.merchantPropertyDao.queryMerchantPropertyById(id);
	}

	// 查询商家信息
	@Override
	public PageModelMerChantProperty queryMerchantProperty(int offset,
			int pagesize) {
		// TODO Auto-generated method stub

		List<MerchantProperty> list = this.merchantPropertyDao
				.queryMerchantProperty(offset, pagesize);

		int total = this.queryMerchantPropertyCount();

		int totalpage = 0;

		if (total % pagesize == 0) {

			totalpage = total / pagesize;

		} else {

			totalpage = (total / pagesize) + 1;

		}

		PageModelMerChantProperty pageModelMerChantProperty = new PageModelMerChantProperty();

		pageModelMerChantProperty.setList(list);

		pageModelMerChantProperty.setTotal(total);

		pageModelMerChantProperty.setTotalpage(totalpage);

		return pageModelMerChantProperty;
	}

	// 查询商家总条目数
	@Override
	public int queryMerchantPropertyCount() {
		// TODO Auto-generated method stub
		return this.merchantPropertyDao.queryMerchantPropertyCount();
	}

}
